﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using NUnit.Framework;
using ShrinkWrap.HttpHandler;

namespace ShrinkWrap.Test.HttpHandler
{
    [TestFixture]
    public class CompositeUriFixture
    {
        [TestCase("http://google.com/", new String[] {"http://google.com/"} )]
        [TestCase("http://google.com", new String[] { "http://google.com" })]
        [TestCase("http://google.com/foo.js", new String[] { "http://google.com/foo.js" })]
        [TestCase("http://google.com/foo.css", new String[] { "http://google.com/foo.css" })]
        [TestCase("http://google.com/foo", new String[] { "http://google.com/foo" })]
        [TestCase("http://google.com/+foo", new String[] { "http://google.com/", "http://google.com/foo" })]
        [TestCase("http://google.com/foo.js+bar.js", new String[] { "http://google.com/foo.js", "http://google.com/bar.js" })]
        [TestCase("http://google.com/foo.css+bar.css+john.css", new String[] { "http://google.com/foo.css", "http://google.com/bar.css", "http://google.com/john.css" })]
        [TestCase("http://google.com/some/path/foo.css+bar.css", new String[] { "http://google.com/some/path/foo.css", "http://google.com/some/path/bar.css" })]
        [TestCase("http://google.com/some/path/", new String[] { "http://google.com/some/path/" })]
        [TestCase("http://google.com/some/path/foo.css?q=23", new String[] { "http://google.com/some/path/foo.css?q=23" })]
        [TestCase("http://google.com/some/path/foo.css+bar.css?q=23", new String[] { "http://google.com/some/path/foo.css?q=23", "http://google.com/some/path/bar.css?q=23" })]
        [TestCase("http://google.com/some/path/foo.css+bar.css?q=23&id=yes", new String[] { "http://google.com/some/path/foo.css?q=23&id=yes", "http://google.com/some/path/bar.css?q=23&id=yes" })]
        public void TestDerivingConstituentUris(String composite, String[] expectedConstituents)
        {
            var plainUri = new Uri(composite);
            var compositeUri = new CompositeUri( plainUri );

            var expectedConstituentUris = expectedConstituents.Select(s => new Uri(s));              

            Assert.AreEqual( expectedConstituentUris.ToList(), compositeUri.ConstituentUris );
        }

        [TestCase("http://google.com/some/path/foo.js+bar.css", true)]
        [TestCase("http://google.com/some/path/foo.js+bar.css+john.js", true)]
        [TestCase("http://google.com/some/path/foo+bar.css", true)]
        [TestCase("http://google.com/some/path/foo.css+bar.css", false)]
        [TestCase("http://google.com/some/path/foo+bar", false)]
        [TestCase("http://google.com/some/path/foo", false)]
        [TestCase("http://google.com/some/path/foo.js", false)]
        [TestCase("http://google.com/some/path/", false)]
        [TestCase("http://google.com/some/path/?hello=world", false)]
        [TestCase("http://google.com/some/path/foo.js+bar.js?query=something", false)]
        public void TestFileExtensionsDiffer(String composite, bool isDifferent)
        {
            var plainUri = new Uri(composite);
            var compositeUri = new CompositeUri(plainUri);

            Assert.AreEqual(compositeUri.HasDifferingFileExtensions, isDifferent);
        }
    }
}
